<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="生产订单号">
              <a-input placeholder="请输入生产订单号" v-model="queryParam.productOrdNo"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="装置编号">
              <a-input placeholder="请输入装置编号" v-model="queryParam.unitNo"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :md="12" :sm="16">
              <a-form-item label="组装完成时间">
                <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" class="query-group-cust" v-model="queryParam.endTime_begin"></j-date>
                <span class="query-group-split-cust"></span>
                <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" class="query-group-cust" v-model="queryParam.endTime_end"></j-date>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="6" :sm="8" >
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-dropdown>
        <a-button @click="batchUpdate()" type="primary"  icon="rollback">批量审批</a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <template>
            <a @click="handleDetail(record)">查看</a>|
            <a @click="batchUpdate(record)">审核</a>
            <a-divider type="vertical"/>
          </template>
        </span>

      </a-table>
    </div>

    <zxjEip2cZzzz-modal ref="modalForm" @ok="modalFormOk"></zxjEip2cZzzz-modal>
  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ZxjEip2cZzzzModal from './modules/ZxjEip2cZzzzModal'
  import JDate from '@/components/jeecg/JDate.vue'
  import { getAction,putAction,postAction } from '@/api/manage'
  export default {
    name: "ZxjEip2cZzzzList",
    mixins:[JeecgListMixin],
    components: {
      JDate,
      ZxjEip2cZzzzModal
    },
    data () {
      return {
        description: '装置组装管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'生产订单号',
            align:"center",
            dataIndex: 'productOrdNo'
          },
          {
            title:'装置编号',
            align:"center",
            dataIndex: 'unitNo'
          },
          {
            title:'工序类型',
            align:"center",
            dataIndex: 'processType'
          },
          {
            title:'组装完成时间',
            align:"center",
            dataIndex: 'endTime'
          },
          {
            title:'板卡编号',
            align:"center",
            dataIndex: 'boardNo'
          },
          {
            title:'软件版本',
            align:"center",
            dataIndex: 'softVersion'
          },
          {
            title:'抓取状态',
            align:"center",
            dataIndex: 'ioflag',
            customRender:function (text) {
              return !text?"":(text == 0?'已抓取':'未抓取')
            }
          },
          {
            title:'抓取时间',
            align:"center",
            dataIndex: 'updateTime'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
        url: {
          list: "/apis/zxjEip2cZzzz/list",
          updateBatch: "/apis/zxjEip2cZzzz/updateBatch",
        },
        dictOptions:{
        } 
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      initDictConfig(){
      },
      batchUpdate(record){
        //alert(record.contractNumber);
        var that = this;
        var rows = that.selectionRows;
        console.log(that.selectionRows.length);
        if(rows.length<=0 && record == null){
          this.$message.warning('请选择一条记录！');
          return;
        }else {
          that.$confirm({
            title:"确认操作",
            content:"是否审核?",
            onOk: function(){
              var param = {data:[]};
              var data = {};
              if(record!=null){
                data = {tid:record.tid};
                param.data.push(data);
              }else{
                for (var i = 0; i < rows.length; i++) {
                  data = {tid:rows[i].tid};
                  param.data.push(data);
                }
              }
              console.log(param.data);
              postAction(that.url.updateBatch,param.data).then((res)=>{
                if(res.success){
                  that.$message.success(res.message);
                  that.loadData();
                }
              });

            }
          });
        }
      },
      handleDetail(record){
        this.$refs.modalForm.addModal(record);
        this.$refs.modalForm.title="详细信息";
      }
    }
  }
</script>